package com.bwie.controller;

import com.bwie.common.domain.User;
import com.bwie.common.domain.UserRole;
import com.bwie.common.result.Result;
import com.bwie.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @className: UserController
 * @Description: TODO
 * @version: v1.８.0
 * @author: 房新路
 * @date: 2025/8/4 10:23
 */
@RestController
@RequestMapping("user")
public class UserController {
    /**
     * 根据用户名查询用户的信息
     * @param username
     * @return
     */
    @Autowired
    private UserService userService;
    @GetMapping("findByUsername/{username}")
    public Result<User> findByUsername(@PathVariable("username") String username){
       User data=userService.findByUsername(username);
        return Result.success(data);
    }
    /**
     * 根据用户ID查询角色信息的信息
     * @param userId
     * @return
     */
    @GetMapping("findByRole/{userId}")
    public Result<UserRole> findByRole(@PathVariable("userId") Integer userId){
        UserRole data=userService.findByRole(userId);
        return Result.success(data);
    }
}